package com.coffee.tenant;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import com.coffee.mybatis.CoffeeMybatisInterceptor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author songkui
 * @since 2024/4/17 13:44
 */
@Configuration(proxyBeanMethods = false)
public class TenantConfiguration {

    @Bean
    public FilterRegistrationBean<TenantContextWebFilter> registration(CoffeeWebTenantDecider tenantDecider) {
        FilterRegistrationBean<TenantContextWebFilter> registration = new FilterRegistrationBean<>(new TenantContextWebFilter(tenantDecider));
        registration.setEnabled(false);
        return registration;
    }


    @Bean
    public TenantLineInnerInterceptor tenantLineInnerInterceptor(CoffeeTenantConfigProperties properties, MybatisPlusInterceptor interceptor) {
        TenantLineInnerInterceptor inner = new TenantLineInnerInterceptor(new CoffeeTenantLineHandler(properties));
        CoffeeMybatisInterceptor.addInterceptor(interceptor, inner, 0);
        return inner;
    }

    @Bean
    public CoffeeIgnoreTenantAspect coffeeIgnoreTenantAspect(){
        return new CoffeeIgnoreTenantAspect();
    }

}
